package cn.swu.homework1

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

val food = arrayListOf<Food>()
class ListActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_list)
        initdata()
        val recycler=findViewById<RecyclerView>(R.id.recycler)
        recycler.layoutManager=LinearLayoutManager(this)
        recycler.adapter=FoodAdapter(food)
    }

    private fun initdata() {
        for(i in 1..10)
        {
            food.add(Food().apply {
                name = "多肉葡萄"
                description = "多多的葡萄，多多的芝士，家人们，就是说一整个nice！"
                picture = R.mipmap.grape
            })
            food.add(Food().apply {
                name = "杨枝甘露"
                description = "清凉解渴！享受果味！沁人心脾！"
                picture = R.mipmap.yangzhi
            })
            food.add(Food().apply {
                name = "雪王大圣代（奥利奥）"
                description = "夏天的必需品！便宜实惠冲啊！"
                picture = R.mipmap.ice
            })
        }
    }
}